using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace ELS.Configuration.UserInterface
{
	/// <summary>
	/// Summary description for ConfigurationPropertyEditor.
	/// </summary>
	public class ConfigurationPropertyEditor : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label lblPropertyName;
		private System.Windows.Forms.Label lblPropertyValue;
		private Infragistics.Win.UltraWinEditors.UltraTextEditor ultraTextEditor1;
		private ConfigurationProperty _configProperty = null;
		private System.Windows.Forms.Button btnCancel;
		private System.Windows.Forms.Button btnOk;
		private System.Windows.Forms.TextBox txtPropertyName;
		private System.Windows.Forms.TextBox txtPropertyValue;

		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public ConfigurationPropertyEditor( ConfigurationProperty configProperty )
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

			_configProperty = configProperty;
			this.Load+=new EventHandler(ConfigurationPropertyEditor_Load);
		}

		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Component Designer generated code
		/// <summary> 
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(ConfigurationPropertyEditor));
			this.lblPropertyName = new System.Windows.Forms.Label();
			this.lblPropertyValue = new System.Windows.Forms.Label();
			this.ultraTextEditor1 = new Infragistics.Win.UltraWinEditors.UltraTextEditor();
			this.btnCancel = new System.Windows.Forms.Button();
			this.btnOk = new System.Windows.Forms.Button();
			this.txtPropertyName = new System.Windows.Forms.TextBox();
			this.txtPropertyValue = new System.Windows.Forms.TextBox();
			((System.ComponentModel.ISupportInitialize)(this.ultraTextEditor1)).BeginInit();
			this.SuspendLayout();
			// 
			// lblPropertyName
			// 
			this.lblPropertyName.AutoSize = true;
			this.lblPropertyName.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F);
			this.lblPropertyName.Location = new System.Drawing.Point(8, 8);
			this.lblPropertyName.Name = "lblPropertyName";
			this.lblPropertyName.Size = new System.Drawing.Size(105, 19);
			this.lblPropertyName.TabIndex = 1;
			this.lblPropertyName.Text = "Property Name :";
			// 
			// lblPropertyValue
			// 
			this.lblPropertyValue.AutoSize = true;
			this.lblPropertyValue.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F);
			this.lblPropertyValue.Location = new System.Drawing.Point(8, 64);
			this.lblPropertyValue.Name = "lblPropertyValue";
			this.lblPropertyValue.Size = new System.Drawing.Size(103, 19);
			this.lblPropertyValue.TabIndex = 3;
			this.lblPropertyValue.Text = "Property Value :";
			// 
			// ultraTextEditor1
			// 
			this.ultraTextEditor1.Location = new System.Drawing.Point(0, 72);
			this.ultraTextEditor1.Name = "ultraTextEditor1";
			this.ultraTextEditor1.Size = new System.Drawing.Size(376, 21);
			this.ultraTextEditor1.TabIndex = 0;
			// 
			// btnCancel
			// 
			this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.btnCancel.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F);
			this.btnCancel.Location = new System.Drawing.Point(464, 128);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.TabIndex = 2;
			this.btnCancel.Text = "Cancel";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// btnOk
			// 
			this.btnOk.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F);
			this.btnOk.Location = new System.Drawing.Point(384, 128);
			this.btnOk.Name = "btnOk";
			this.btnOk.TabIndex = 1;
			this.btnOk.Text = "Ok";
			this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
			// 
			// txtPropertyName
			// 
			this.txtPropertyName.Location = new System.Drawing.Point(8, 32);
			this.txtPropertyName.Name = "txtPropertyName";
			this.txtPropertyName.ReadOnly = true;
			this.txtPropertyName.Size = new System.Drawing.Size(528, 23);
			this.txtPropertyName.TabIndex = 4;
			this.txtPropertyName.Text = "";
			// 
			// txtPropertyValue
			// 
			this.txtPropertyValue.Location = new System.Drawing.Point(8, 88);
			this.txtPropertyValue.Name = "txtPropertyValue";
			this.txtPropertyValue.Size = new System.Drawing.Size(528, 23);
			this.txtPropertyValue.TabIndex = 5;
			this.txtPropertyValue.Text = "";
			// 
			// ConfigurationPropertyEditor
			// 
			this.AcceptButton = this.btnOk;
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 16);
			this.CancelButton = this.btnCancel;
			this.ClientSize = new System.Drawing.Size(554, 160);
			this.Controls.Add(this.txtPropertyValue);
			this.Controls.Add(this.txtPropertyName);
			this.Controls.Add(this.btnCancel);
			this.Controls.Add(this.btnOk);
			this.Controls.Add(this.lblPropertyValue);
			this.Controls.Add(this.lblPropertyName);
			this.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.HelpButton = true;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "ConfigurationPropertyEditor";
			this.Text = "Edit Property";
			((System.ComponentModel.ISupportInitialize)(this.ultraTextEditor1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void ConfigurationPropertyEditor_Load(object sender, EventArgs e)
		{
			if ( _configProperty != null )
			{
				txtPropertyName.Text = _configProperty.FullName;
				txtPropertyValue.Text = (_configProperty.Values.Count > 0 )? _configProperty.Values[0] : null;
			}
		}

		private void btnOk_Click(object sender, System.EventArgs e)
		{
			string propValue = txtPropertyValue.Text.Trim();
			if ( propValue != String.Empty )
				_configProperty.Value = txtPropertyValue.Text;
			
			this.DialogResult = DialogResult.OK;
			this.Close();
		}

		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			this.DialogResult = DialogResult.Cancel;
			this.Close();
		}
	}
}
